package sk.sodik.atomFilter.feeds;

import java.util.logging.Logger;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class EMF {
	private static final EntityManagerFactory emfInstance = Persistence
			.createEntityManagerFactory("transactions-optional");
	private static final Logger log = Logger.getLogger(EMF.class.getName());

	private EMF() {
	}

	public static EntityManagerFactory get() {
		return emfInstance;
	}

	public static FeedFilter load(FeedFilterId key) {
		EntityManager em = get().createEntityManager();
		try {
			log.fine("Going to find " + key);
			FeedFilter obj = em.find(FeedFilter.class, key.toString());

			log.finer("Found?" + (obj != null));
			return obj;
		} finally {
			em.close();
		}
	}
}
